package com.hunan.api.catv.service.impl.tencent_cloud.vod;

import com.google.gson.JsonObject;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.vod.v20180717.VodClient;
import com.tencentcloudapi.vod.v20180717.models.DeleteMediaRequest;
import com.tencentcloudapi.vod.v20180717.models.DeleteMediaResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

@Service
public class VodService {

    public static Logger log = LoggerFactory.getLogger(VodService.class);

    public boolean deleteMedia(String secretId, String secretKey, String fileId) {
        try {
            Credential cred = new Credential(secretId, secretKey);
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("vod.tencentcloudapi.com");
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);
            VodClient client = new VodClient(cred, "", clientProfile);
            JsonObject params = new JsonObject();
            params.addProperty("FileId", fileId);
            ;
            DeleteMediaRequest req = DeleteMediaRequest.fromJsonString(params.toString(), DeleteMediaRequest.class);
            DeleteMediaResponse resp = client.DeleteMedia(req);
            String result = DeleteMediaResponse.toJsonString(resp);
            if (!ObjectUtils.isEmpty(result)) {
                return true;
            }
        } catch (Exception e) {
            log.error("删除媒体失败：{}", e);
        }
        return false;
    }
}
